package com.cuijq.counterv2.controller;

import com.cuijq.counterv2.entity.RequestInfo;
import com.cuijq.counterv2.service.MetricsStorage;
import io.micrometer.core.instrument.util.StringUtils;

/**
 * @Classname MetricsCollector
 * @Description TODO
 * @Date 2021/4/30 14:00
 * @Created by CuiJQ
 */
public class MetricsCollector {


  private MetricsStorage metricsStorage;//基于接口而非实现编程

  // 依赖注入
  public MetricsCollector(MetricsStorage metricsStorage) {
    this.metricsStorage = metricsStorage;
  } //用一个函数代替了最小原型中的两个函数

  public void recordRequest(RequestInfo requestInfo) {
    if (requestInfo == null || StringUtils.isBlank(requestInfo.getApiName())) {
      return;
    }
    metricsStorage.saveRequestInfo(requestInfo);
  }
}
